package com.example.john.ksoap2android;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class AdapterTestActivity extends AppCompatActivity {

    private ListView lv;
    private String[] data=new String[]{"abc","bcd","xxer"};
    private LayoutInflater inflater;
    private List<Food> foods=new ArrayList<Food>();
    private int[] snaps=new int[]{R.drawable.a1,R.drawable.a2,R.drawable.a3};
    private  FoodAdapter adapter;

    private  void init(){
        for(int i=0;i<snaps.length;i++){
            Food f=new Food();
            f.setFoodName("foodName...."+i);
            f.setDetail("detail........" + i);
            f.setSnap(snaps[i]);
            foods.add(f);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adapter_test);
        init();
        inflater=getLayoutInflater();
        adapter=new FoodAdapter(foods,inflater);


        lv=(ListView)findViewById(R.id.lv);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(AdapterTestActivity.this,data[position].toString(),Toast.LENGTH_LONG).show();
                Log.i("john",data[position]);
            }
        });
    }


    public void test(View view) {
        lv.setAdapter(adapter);
    }
}
